﻿using System;

namespace ControleRepresentanteSync.Application.Wizard
{
    class LazyWizardPageProvider : IWizardPageProvider
    {
        private readonly Func<IWizardPageViewModel> m_Func;
        private IWizardPageViewModel m_WizardPageViewModel;

        public LazyWizardPageProvider(Func<IWizardPageViewModel> func)
        {
            m_Func = func;
            if (Changed != null){}
        }

        public IWizardPageViewModel Current
        {
            get
            {
                if (m_WizardPageViewModel != null)
                {
                    m_WizardPageViewModel.FireOnClose();
                }
                m_WizardPageViewModel = m_Func();
                return m_WizardPageViewModel;
            }
        }
        public bool CanGoBack { get { return false; } }
        public bool IsFinish { get { return true; } }

        public IWizardPageViewModel MoveNext()
        {
            throw new NotImplementedException();
        }

        public IWizardPageViewModel MoveBack()
        {
            throw new NotImplementedException();
        }

        public event EventHandler Changed;
        
        public void Dispose()
        {
            if (m_WizardPageViewModel != null)
            {
                m_WizardPageViewModel.FireOnClose();
            }
        }
    }
}
